<!--
<div class="container-fluid" >
<div class="row" >
<div class="col-sm-3 col-md-4 sidebar">
		<fieldset class="cad">
		<legend>Cadastro Ligações</legend>
		<form class="form-horizontal" id="form" role="form">
			  <div class="form-group">
				<label for="inputEmail3" class="col-sm-2 control-label">Ramal</label>
				<div class="col-sm-4">
				  <input type="text" class="form-control input-sm" id="ramal" name="ramal" placeholder="Ramal">
				</div>
			  </div>
			  <div class="form-group">
				<label for="inputEmail3" class="col-sm-2 control-label">De</label>
				<div class="col-sm-10">
				  <input type="text" class="form-control input-sm" id="solicitante" name="solicitante" placeholder="De">
				</div>
			  </div>
			  <div class="form-group">
				<label for="inputEmail3" class="col-sm-2 control-label">Telefone</label>
				<div class="col-sm-4">
				  <input type="text" class="form-control input-sm" id="telefone" name="telefone" placeholder="Telefone">
				</div>
			  </div>
			  <div class="form-group">
				<label for="inputEmail3" class="col-sm-2 control-label">Para</label>
				<div class="col-sm-10">
				  <input type="text" class="form-control input-sm" id="solicitado" name="solicitado" placeholder="Para">
				</div>
			  </div>
			  <div class="form-group">
				<label for="inputEmail3" class="col-sm-2 control-label">Assunto</label>
				<div class="col-sm-10">
				  <textarea class="form-control input-sm" id="assunto" name="assunto"  placeholder="Assunto">A SERVICO</textarea>
				</div>
			  </div>
			  
			<div class="form-group">
				<label for="inputEmail3" class="col-sm-2 control-label">Tipo</label>
				<div class="col-sm-5">
					<select name="tipoligacao" id="tipoligacao" class="form-control input-sm">
						<option value="1">LOCAL</option>
						<option value="2">INTERURBANO</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-offset-2 col-sm-10">
					<button type="submit" class="btn btn-primary">Registrar</button>
					<a id="cancelar" href="<?php echo base_url('/index.php/inicio/atendimento');?>" class="btn btn-default"></span>Cancelar</a>
				</div>
			</div>
		</form>
		</fieldset>
	</div>
<div class="col-md-8">
<fieldset>
<legend>Ligações Pendentes</legend>
<table id="example" class="display responsive nowrap" cellspacing="0" width="100%">
      <thead>
        <tr>
          <th>Data/Hora</th>
          <th>Ramal</th>
          <th>De</th>
          <th>Telefone</th>
          <th>Para</th>
          <th>Assunto</th>
          <th></th>
        </tr>
      </thead>
      <tbody>
		<?php
			foreach($atendimentos as $atendimento){
				echo '<tr>';
				echo '<td>'.$atendimento->dt_cadastro.'</td>';
				echo '<td>'.$atendimento->ramal.'</td>';
				echo '<td>'.$atendimento->solicitante.'</td>';
				echo '<td style="color:blue;font-weight:bold;">'.$atendimento->telefone.'</td>';
				echo '<td style="color:green;font-weight:bold;">'.$atendimento->solicitado.'</td>';
				echo '<td>'.$atendimento->assunto.'</td>';
				echo '<td>';
				echo '<select name="status" id="status" class="form-control input-sm">
					<option value="1"></option>
					<option value="2">Caixa de Mensagem</option>
					<option value="3">Contato não existe</option>
					<option value="4">Ligação realizada</option>
					<option value="5">Não atende</option>
					<option value="6">Telefone ocupado</option>
					<option value="7">Outros</option>
				</select>';
				echo '<a data-toggle="modal" href="'.base_url('index.php/partes/info/'.$atendimetno->id).'" class="btn btn-success btn-xs"><span class="glyphicon glyphicon-plus"></span>Aguardar</a></td>';
				echo ' </tr>';

			}
		?>	  
		
      </tbody>
    </table>
	</fieldset>
</div>
</div>
</div> -->

<div class="container-fluid" >
		<fieldset class="cad">
		<legend>Cadastro Ligações</legend>
		<form class="form-inline" role="form" id="form">
			  
			  <div class="form-group">
				<div class="input-group">
				  <label for="">Ramal</label>
				  <input type="text" class="form-control input-sm" id="ramal" name="ramal" placeholder="Ramal">
				</div>
			  </div>
			  
			  <div class="form-group">
				<div class="input-group">
				  <label for="">De</label>
				  <input type="text" class="form-control input-sm"  id="solicitante" name="solicitante" placeholder="De">
				</div>
			  </div>
			  
			  <div class="form-group">
				<div class="input-group">
				  <label for="">Telefone</label>
				  <input type="text" class="form-control input-sm"  id="telefone" name="telefone" placeholder="Telefone">
				 
				</div>
			  </div>
		 
			  <div class="form-group">
				<div class="input-group">
				  <label for="">Para</label>
				  <input type="text" class="form-control input-sm"  id="solicitado" name="solicitado" placeholder="Para" value="NÃO INFORMADO">
				</div>
			  </div>

			  <div class="form-group">
				<div class="input-group">
				  <label for="">Assunto</label>
				  <input type="text" class="form-control input-sm"   id="assunto" name="assunto" value="A SERVIÇO" >
				</div>
			  </div>
			  
			   <div class="form-group">
				<div class="input-group">
				  <label for="">Tipo</label>
					<select name="tipoligacao" id="tipoligacao" class="form-control input-sm">
						<option value="1">LOCAL</option>
						<option value="2">INTERURBANO</option>
					</select>
				</div>
			  </div>
			  <br/>
			  <br/>
			  <div class="form-group">
				<div class="input-group">
					<button type="submit" class="btn btn-primary">Registrar</button> 
					<a style="margin-left: 5px;" id="cancelar" href="<?php echo base_url('/index.php/inicio/atendimento');?>" class="btn btn-default"></span>Cancelar</a>
				</div>
			  </div>
			   <br/>
		</form>
		</fieldset>
		<form role="form" id="fila">
			<div class="form-group">
					<div class="input-group">
					  <label for="">Tipo Ligação</label>
							<select class="form-control input-sm" name="status" id="status" >
									<option value=""> -- SELECIONE PARA FINALIZAR -- </option>
									<option value="2">Caixa de Mensagem</option>
									<option value="3">Contato não existe</option>
									<option value="4">Ligação realizada</option>
									<option value="5">Não atende</option>
									<option value="6">Telefone ocupado</option>
									<option value="7">Outros</option>
							</select>
					</div>
			</div>
			<div class="form-group">
			<div class="input-group">
					<button type="submit" id="myButton" data-loading-text="Loading..." class="btn btn-danger ">Finalizar</button>
					<a style="margin-left: 5px;" id="cancelar" href="<?php echo base_url('/index.php/inicio/atendimento');?>" class="btn btn-default"></span>Cancelar</a>
			</div>
			</div>

			<table id="example" class="display responsive nowrap" cellspacing="0" width="100%">
			  <thead>
				<tr>
				  <th>#</th>
				  <th>Data/Hora</th>
				  <th>Ramal</th>
				  <th>De</th>
				  <th>Telefone</th>
				  <th>Para</th>
				  <th>Assunto</th>
				  <th>Aguardar</th>
				  <th>Tentativas</th>
				 <!-- <th>Finalizar</th>-->
				</tr>
			  </thead>
			  <tbody>
				<?php
					foreach($atendimentos as $atendimento){
						echo '<tr>';
						echo '<td><input type="checkbox" name="id[]" value="'.$atendimento->id.'"></td>';
						echo '<td>'.$atendimento->dt_cadastro.'</td>';
						echo '<td>'.$atendimento->ramal.'</td>';
						echo '<td>'.$atendimento->solicitante.'</td>';
						echo '<td style="color:blue;font-weight:bold;">'.$atendimento->telefone.'</td>';
						echo '<td style="color:green;font-weight:bold;">'.$atendimento->solicitado.'</td>';
						echo '<td>'.$atendimento->assunto.'</td>';
						echo '<td>';
						echo '<a style="margin-right: 5px;" data-toggle="modal" href="#" onclick=aguardar("'.$atendimento->id.'"); class="btn btn-success btn-xs"><span class="glyphicon glyphicon-refresh"></span> Aguardar</a>';
						echo '<a data-toggle="modal" href="'.base_url('index.php/inicio/atendimentoModal/'.$atendimento->id).'" class="btn btn-primary btn-xs" data-target="#myassunto"><span class="glyphicon glyphicon-edit"></span> Editar</a></td>';
						echo '<td>';
						$i = 0;
						while( $i < $atendimento->tentativas){
							echo '<img src="'.base_url('includes/images/times.png').'" >';
							$i++;
						}
						echo '</td>';
						/*echo '<td><select name="status" id="status" class="form-control input-sm">
							<option value="1"></option>
							<option value="2">Caixa de Mensagem</option>
							<option value="3">Contato não existe</option>
							<option value="4">Ligação realizada</option>
							<option value="5">Não atende</option>
							<option value="6">Telefone ocupado</option>
							<option value="7">Outros</option>
						</select>';
						//echo '<a style="margin-left: 5px;" data-toggle="modal" href="#" onclick=finalizar("'.$atendimento->id.'"); class="btn btn-danger btn-xs"><span class="glyphicon glyphicon-download-alt"></span> Finalizar</a>';
						echo '<button style="margin-left: 5px;" type="button" id="myButton" data-loading-text="Loading..." class="btn btn-danger btn-xs">Finalizar</button>';
						echo '</td>';*/
						echo ' </tr>';

					}
				?>	  
				
				</tbody>
			</table>
			 <!--<div class="form-group">
				<div class="input-group">
				  <label for="">Tipo Ligação</label>
					<select class="form-control input-sm" name="status" id="status" >
						<option value=""> -- SELECIONE TIPO LIGAÇÃO -- </option>
						<option value="2">Caixa de Mensagem</option>
						<option value="3">Contato não existe</option>
						<option value="4">Ligação realizada</option>
						<option value="5">Não atende</option>
						<option value="6">Telefone ocupado</option>
						<option value="7">Outros</option>
					</select>
				</div>
			</div>
			<div class="form-group">
			<div class="input-group">
				<button type="submit" id="myButton" data-loading-text="Loading..." class="btn btn-danger ">Finalizar</button>
				<a style="margin-left: 5px;" id="cancelar" href="<?php echo base_url('/index.php/inicio/atendimento');?>" class="btn btn-default"></span>Cancelar</a>
			</div>
			</div> -->
		</form>
</div>
<div class="modal bs-example-modal-lg" id="myassunto" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">		
		
    </div>
        <!-- /.modal-content -->
		
    </div>
    <!-- /.modal-dialog -->
</div>
<script type="text/javascript">
    $(document).ready(function(){
		$("#ramal").focus()
		$("#ramal").mask('9999');
		var maskBehavior = function (val) {
			return val.replace(/\D/g, '').length === 11 ? '(00) 00000-0000' : '(00) 0000-00009';
		},
		options = {onKeyPress: function(val, e, field, options) {
				field.mask(maskBehavior.apply({}, arguments), options);
			}
		};
		$("#telefone").mask(maskBehavior, options);
		var oTable = $('#example').DataTable({
			"paging": false,
			"searching": false,
			"info": false,
			"ordering":  false,
			"columns": [
			{ "width": "1%" },
			{ "width": "5%" },
			{ "width": "5%" },
			null,
			{ "width": "5%" },
			null,
			null,
			{ "width": "5%" },
			{ "width": "10%" }
		  ]
		});
		$('#example tbody').on( 'click', 'tr', function () {
			$(this).toggleClass('selected');
		});
		$('#form').validate({  
			rules: {  
				ramal: { required: true },
				solicitante: { required: true },
				//telefone: { required: true },
				telefone: { required: true, remote: '<?php echo base_url('index.php/inicio/validaTelefone');?>' },
				solicitado: { required: true }
				
			},  
			messages: {  
				ramal: { required: 'Preencha o campo'},
				solicitante: { required: 'Preencha o campo'},
				//telefone: { required: 'Preencha o campo'},
				telefone: { required: 'Preencha o telefone', remote: ' Telefone em atendimento!' },
				solicitado: { required: 'Preencha o campo'}
			},
			submitHandler: function( form ){  
				var dados = $( form ).serialize();  
				$.ajax({  
					type: "POST",  
					url: "<?php echo base_url('index.php/inicio/salvar');?>",  
					data: dados,  
					success: function( data )  
					{  
						window.location = "<?php echo base_url('index.php/inicio/atendimento');?>";
					}  
				});  
				return false;  
			} 
		}); 
		
		//------------------------------------------
		$('#fila').validate({  
			rules: {  
				status: { required: true },
				id: { required: true }
				
			},  
			messages: {  
				status: { required: 'Preencha o campo'},
				id: { required: 'Preencha o campo'}
			},
			submitHandler: function( form ){  
				var dados = $(form).serialize();  
				//alert(dados);
				$.ajax({  
					type: "POST",  
					url: "<?php echo base_url('index.php/inicio/finalizar');?>",  
					data: dados,  
					success: function( data )  
					{  
						//window.location = "<?php echo base_url('index.php/inicio/atendimento');?>";
						window.location = "<?php echo base_url('index.php/inicio/atendimento');?>";
					}  
				});  
				return false;  
			}

		}); 

		

	
	});
	
	function aguardar(id){
		var dados = "id=" + id;
		$.ajax({  
			type: "POST",  
			url: "<?php echo base_url('index.php/inicio/aguardar');?>",  
			data: dados,  
			success: function( data )  
			{  
				window.location = "<?php echo base_url('index.php/inicio/atendimento');?>";
			}  
		});  
		return false;  
	}
	
	
	function finalizar(id){
		//var dados = "id=" + id + 'status='+ '';
		var data = otable.$('input, select').serialize();
		alert(data);
		/*$.ajax({  
			type: "POST",  
			url: "<?php echo base_url('index.php/inicio/aguardar');?>",  
			data: dados,  
			success: function( data )  
			{  
				window.location = "<?php echo base_url('index.php/inicio/atendimento');?>";
			}  
		});  
		return false;  
		*/
	}
</script>
</body>
</html>